package com.zzq.my.jetpacks.jectpackapp.adapter

import android.annotation.SuppressLint
import android.widget.TextView
import androidx.core.content.ContextCompat
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.hjq.shape.view.ShapeTextView
import com.zzq.my.jetpacks.jectpackapp.R
import com.zzq.my.jetpacks.jectpackapp.bean.AutoSelectItem

/**
 * 描述：文本适配器
 * 作者：zhuangzeqin
 * 时间: 2022/1/19-14:16
 * 邮箱：zzq@eeepay.cn
 * 备注:
 */
class AutoSelectItemAdapter:BaseQuickAdapter<AutoSelectItem,BaseViewHolder>(R.layout.shop_incoming_item_filter_txt){
    /**
     * Implement this method and use the helper to adapt the view to the given item.
     *
     * 实现此方法，并使用 helper 完成 item 视图的操作
     *
     * @param holder A fully initialized helper.
     * @param item   The item that needs to be displayed.
     */
    override fun convert(holder: BaseViewHolder, item: AutoSelectItem) {
        holder.setText(R.id.tv_type,item.name)
        if (item.isChecked)
        {
            holder.setTextColor(R.id.tv_type,ContextCompat.getColor(context,R.color.color_3887EB))
            holder.setBackgroundResource(R.id.tv_type,R.drawable.btn_submit_select_bg_pre)
        }
        else
        {
            holder.setTextColor(R.id.tv_type,ContextCompat.getColor(context,R.color.color_666666))
            holder.setBackgroundResource(R.id.tv_type,R.drawable.btn_submit_select_bg_not)
        }
    }

    @SuppressLint("NotifyDataSetChanged")
    fun cleanCheck() {
        data.forEachIndexed { index, autoSelectItem ->
            autoSelectItem.isChecked = false
        }
        notifyDataSetChanged()

    }

    /**
     * 获得选择的item
     */
   fun getCheckedData():AutoSelectItem?
    {
        var item :AutoSelectItem? = null
        data.also {
            it.forEachIndexed { index, autoSelectItem ->
                if (autoSelectItem.isChecked)
                {
                    item = autoSelectItem
                    return@also
                }
            }
        }
        return item
    }
}